package com.datastructure.test.doubletoken.lengthofnorepeatstring;

import java.util.HashMap;
import java.util.Map;

public class LengthOfNoRepeatedString {

    public static void main(String[] args) {
        LengthOfNoRepeatedString lengthOfNoRepeatedString = new LengthOfNoRepeatedString();
        int[] data = {32,41,32};
        System.out.println(lengthOfNoRepeatedString.getLength(data));
    }

    public int getLength(int [] data){
        if(data.length==0){
            return 0;
        }
        int max = 0;
        Map<Integer,Integer> result = new HashMap<>();
        for(int i=0,j=0;i< data.length;i++){
            if(result.containsKey(data[i])){
                j = Math.max(j,result.get(data[i])+1);
            }
            result.put(data[i],i);
            max=Math.max(max,i-j+1);
        }
        return max;
    }
}
